package Lianxi.ATM;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 *  Atm选择菜单
 */

public class Mun extends JPanel implements ActionListener {
    private JButton getmony; //取钱
    private JButton savemony; //存钱
    private JButton check; //查询
    private JButton returnBut; //返回
    private JButton transfer; //转账
    private JButton modify; //修改密码
    private Atm frame;


    public Mun(Atm frame) {
        //返回登陆界面
        this.frame = frame;
        this.setLayout(null);
        this.setOpaque(false);
        returnBut = new JButton("返回登陆");
        returnBut.setBounds(650, 300, 100, 50);
        this.add(returnBut);
        returnBut.addActionListener(this);

        //存款按钮
        savemony = new JButton("存款");
        savemony.setBounds(50, 220, 100, 50);
        this.add(savemony);
        savemony.addActionListener(this);

        //取款按钮
        getmony = new JButton("取款");
        getmony.setBounds(50, 300, 100, 50);
        this.add(getmony);
        getmony.addActionListener(this);

        //查询按钮
        check = new JButton("查询");
        check.setBounds(650, 220, 100, 50);
        this.add(check);
        check.addActionListener(this);

        //查询按钮
        modify = new JButton("修改密码");
        modify.setBounds(650, 380, 100, 50);
        this.add(modify);
        modify.addActionListener(this);


        //转账按钮
        transfer = new JButton("转账");
        transfer.setBounds(50, 380, 100, 50);
        this.add(transfer);
        transfer.addActionListener(this);


    }


    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == returnBut) {
            frame.switchPanel("登录");
        } else if (e.getSource() == savemony) {
            frame.switchPanel("存款");
        } else if (e.getSource() == getmony) {
            frame.switchPanel("取款");
        } else if (e.getSource() == transfer) {
            frame.switchPanel("转账");
        } else if (e.getSource() == modify) {
            frame.switchPanel("修改密码");
        } else if (e.getSource() == check) {
            frame.switchPanel("查询");
            String a = frame.getLoginUser().getId(); //获取当前账户ID
            int b = frame.getLoginUser().getMoney(); //获取当前账户金额
            frame.getCheck().getLabel().setText("账户: " + a);  //当前账户
            frame.getCheck().getLabel1().setText("账户余额: " + b); //当前余额

//            frame.getCheck().getLabel().setText("账户："+frame.getUsers().get(frame.getLongin().getCount()).getId());
//            frame.getCheck().getLabel1().setText("当前余额："+frame.getUsers().get(frame.getLongin().getCount()).getMoney());


        }

    }

}

